/*
 * ViewTableData.cpp
 *
 *  Created on: 2011-1-7
 *      Author: Administrator
 */

#include "ViewTableData.h"


TViewTableHeadRowData::TViewTableHeadRowData()
	{
	iDatas =  new (ELeave) CDesC16ArrayFlat(5);
	}

TViewTableHeadRowData::~TViewTableHeadRowData()
	{
	iColumnWidths.Reset();
	iDatas->Reset();
	delete iDatas;
	iDatas = NULL;
	}

void TViewTableHeadRowData::AddDataL(const TDesC& aData)
	{
	iDatas->AppendL(aData);
	}

TPtrC TViewTableHeadRowData::getData(TInt aIndex)
	{
	if (aIndex >=0 && aIndex < iDatas->Count())
		{
		return iDatas->MdcaPoint(aIndex);
		}
	return NULL;
	}

void TViewTableHeadRowData::setData(TInt aIndex,const TDesC& aData)
	{
	if (aIndex >=0 && aIndex < iDatas->Count())
		{
		iDatas->InsertL(aIndex,aData);
		iDatas->Delete(aIndex + 1);
		}
	}

void TViewTableHeadRowData::setColumnWidths(RArray<TInt> aColumnWidths)
	{
	for(TInt i = 0; i < aColumnWidths.Count(); i++)
		{
		iColumnWidths.AppendL(aColumnWidths[i]);
		}
	}

void TViewTableHeadRowData::AddColumnWidthL(TInt aWidth)
	{
	iColumnWidths.AppendL(aWidth);
	}

TInt TViewTableHeadRowData::getColumnWidth(TInt aIndex)
	{
	if (aIndex >= 0 && aIndex < iColumnWidths.Count())
		return iColumnWidths[aIndex];
	return 0;
	}

TInt TViewTableHeadRowData::Count()
	{
	return iDatas->Count();
	}

TViewTableRowData::TViewTableRowData()
	{
	iExtensionData = NULL;
	}

TViewTableRowData::~TViewTableRowData()
	{
	delete iExtensionData;
	iExtensionData = NULL;
	}

const TDesC& TViewTableRowData::ExtensionData()
	{
    if (iExtensionData)
        return *iExtensionData;
    return KNullDesC;
	}

void TViewTableRowData::setExtensionData(const TDesC& aData)
	{
    delete iExtensionData;
    iExtensionData = NULL;
    iExtensionData = aData.AllocL();
	}



CViewTableData::CViewTableData()
	{
	iHeaderRowData = NULL;
	}

CViewTableData::~CViewTableData()
	{
	delete iHeaderRowData;
	iHeaderRowData = NULL;
	iDataRows.ResetAndDestroy();
	iColumnWidths.Reset();
	}

void CViewTableData::AddDataRowL(TViewTableRowData* aRow)
	{
	iDataRows.AppendL(aRow);
	}

TViewTableRowData*CViewTableData::getDataRow(TInt aIndex)
	{
	if (aIndex >= 0 && aIndex < iDataRows.Count())
		return iDataRows[aIndex];
	return NULL;
	}

void CViewTableData::AddColumnWidthL(TInt aWidth)
	{
	iColumnWidths.AppendL(aWidth);
	}

TInt CViewTableData::getColumnWidth(TInt aIndex)
	{
	if (aIndex >= 0 && aIndex < iColumnWidths.Count())
		return iColumnWidths[aIndex];
	return 0;
	}

TInt CViewTableData::Count()
	{
	return iDataRows.Count();
	}

void CViewTableData::setTitleL(const TDesC& aTitle)
	{
	delete iTitle;
	iTitle = NULL;
	iTitle = aTitle.AllocL();
	}

const TDesC& CViewTableData::Title()
	{
	if (iTitle)
		return *iTitle;
	return KNullDesC;
	}
